package org.budo.graph.view.util;

import org.budo.graph.metric.RedisMetric;
import org.budo.support.spring.util.SpringUtil;
import org.springframework.context.ApplicationContext;

/**
 * @author lmw
 */
public class BudoGraphRedisUtil {
    public static Integer redisMaxTotal(ApplicationContext applicationContext) {
        Integer maxTotal = 0;
        String[] beanNames = applicationContext.getBeanNamesForType(RedisMetric.class);
        for (String beanName : beanNames) {
            RedisMetric redisMetric = (RedisMetric) SpringUtil.getBean(applicationContext, beanName);
            maxTotal += redisMetric.getRedisMaxTotal();
        }
        return maxTotal;
    }

    public static Integer redisNumActive(ApplicationContext applicationContext) {
        Integer numActive = 0;
        String[] beanNames = applicationContext.getBeanNamesForType(RedisMetric.class);
        for (String beanName : beanNames) {
            RedisMetric redisMetric = (RedisMetric) SpringUtil.getBean(applicationContext, beanName);
            numActive += redisMetric.getRedisNumActive();
        }
        return numActive;
    }
}